Conditions | 1 |
Paths | 8 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* TODO |
||
61 | fullLog = program.fullLog; |
||
62 | |||
63 | var app = express(); |
||
64 | |||
65 | // 查成绩API,通过GET传入用户名和密码 |
||
66 | View Code Duplication | app.get('/grades', function (req, res, next) { |
|
67 | if (!req.query.id || !req.query.pwd || (req.query.sem && !(/^20\d{2}-20\d{2}-[1-2]$/).test(req.query.sem))) { |
||
68 | res.send({ error: "参数不正确" }); |
||
69 | return; |
||
70 | } |
||
71 | if (fullLog) { |
||
72 | var start = new Date(); |
||
73 | console.log((timeStamp() + 'Started to query the grades: ').cyan + req.query.id.yellow); |
||
1 ignored issue
–
show
|
|||
74 | } |
||
75 | access.login(req.query.id, req.query.pwd, res, function (headers, ires) { |
||
76 | fullLog && console.log((timeStamp() + 'Successfully logged in.').green); |
||
1 ignored issue
–
show
|
|||
77 | |||
78 | var ret = {}; |
||
79 | var $ = cheerio.load(ires.text); |
||
80 | |||
81 | ret.name = escaper.unescape($('.block1text').html()).match(/姓名:.+</)[0].substring(3).replace(/</, ''); |
||
82 | ret.id = req.query.id; |
||
83 | |||
84 | // 实际上xnxq01id为空的时候和GET这个URL的效果是一样的,都是查询所有学期 |
||
85 | superagent |
||
86 | .post('http://csujwc.its.csu.edu.cn/jsxsd/kscj/yscjcx_list') |
||
87 | .set(headers) |
||
88 | .type('form') |
||
89 | .send({ |
||
90 | xnxq01id: req.query.sem |
||
91 | }) |
||
92 | .end(function (err, iires) { |
||
93 | if (err) { |
||
94 | console.log((timeStamp() + 'Failed to get grades page\n' + err.stack).red); |
||
1 ignored issue
–
show
|
|||
95 | res.send({ error: '无法进入成绩页面' }); |
||
96 | return next(err); |
||
97 | } |
||
98 | fullLog && console.log((timeStamp() + 'Successfully entered grades page.').green); |
||
99 | |||
100 | $ = cheerio.load(iires.text); |
||
101 | |||
102 | ret.grades = {}; |
||
103 | ret['subject-count'] = 0; |
||
104 | ret.failed = {}; |
||
105 | ret['failed-count'] = 0; |
||
106 | |||
107 | // 获取成绩列表,如果有补考记录,则以最高分的为准 |
||
108 | $('#dataList tr').each(function (index) { |
||
109 | if (index === 0) { |
||
110 | return; |
||
111 | } |
||
112 | let element = $(this).find('td'); |
||
113 | let title = escaper.unescape(element.eq(3).text().match(/].+$/)[0].substring(1)); |
||
216 |